
import java.util.*;

/**
 * @author LKQ
 * @date 2022/2/28 10:29
 * @description 两次排序，第一次先按值大小排，第二次选取前k个元素进行位置排序
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {-1, -2, 3, 4};
        solution.maxSubsequence(nums, 3);
    }

    public int[] maxSubsequence(int[] nums, int k) {
        int n = nums.length;
        int[][] location = new int[n][2];
        for (int i = 0; i < n; i++) {
            location[i][0] = i;
            location[i][1] = nums[i];
        }
        Arrays.sort(location, (a, b) -> b[1] - a[1]);
        Arrays.sort(location, 0, k, (a, b) -> a[0] - b[0]);
        int[] res = new int[k];
        for (int i = 0; i < k; i++) {
            res[i] = location[i][1];
        }
        return res;
    }
}
